package org.example.springmvc.controller;

import org.example.springmvc.pojo.George;
import org.example.springmvc.pojo.Paige;
import org.example.springmvc.pojo.Season;
import org.example.springmvc.pojo.Tiger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * ClassName: Hello03Controller
 * Package: org.example.springmvc.controller
 * Description:
 *
 * @Author wanghao
 * @Create 2024-07-14 9:47
 * @Version 1.0
 */
@Controller
@RequestMapping("/hello03")
public class Hello03Controller {

    // 1. 演示单个值的数据回显
    @RequestMapping("/h01")
    public String h01(Model model) {
        Tiger tiger = new Tiger(1, "小老虎", 999d);
        model.addAttribute("tiger", tiger);
        return "succ03";
    }

    // 演示带有选择功能的数据回显（单选）
    @RequestMapping("/h02")
    public String h02(Model model) {
        List<Season> seasonList = Arrays.asList(new Season("春天", "1"), new Season("夏天", "2"), new Season("秋天", "3"), new Season("冬天", "4"));
        model.addAttribute("seasonList", seasonList);
        Paige paige = new Paige(1, "小猪佩奇", new Season("春天", "1"));
        model.addAttribute("paige", paige);
        return "succ04";
    }

    // 演示带有选择功能的数据回显（多选）
    @RequestMapping("/h03")
    public String h03(Model model) {
        List<Season> seasonList = Arrays.asList(new Season("春天", "1"), new Season("夏天", "2"), new Season("秋天", "3"), new Season("冬天", "4"));
        model.addAttribute("seasonList", seasonList);

        List<Season> geogreSeasonList = Arrays.asList(
                new Season("夏天", "2"),
                new Season("秋天", "3")
        );
        George george = new George(1, "乔治", geogreSeasonList);
        model.addAttribute("george", george);
        return "succ05";
    }
}
